package com.atguigu.gmall.order.listener;

import com.atguigu.gmall.common.mqconstant.MqConst;
import com.atguigu.gmall.order.service.OrderService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author wk
 * @create 2021-09-14 11:58
 */
@Component
public class OrderInfoListener {

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = MqConst.QUEUE_ORDER_CANCEL)
    public void receiverMessage(Channel channel, Message message, Long orderId) {
        try {
            // 取消订单
            orderService.cancelOrder(orderId);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
